import { contextBridge,ipcRenderer } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'

// Custom APIs for renderer
const api = {
  // 现有的 getMac 方法
  getMac: () => {
    return new Promise((resolve) => {
      ipcRenderer.send('getMac')
      ipcRenderer.on('getMac', (event, arg) => {
        console.log("arg", arg)
        resolve(arg)
      })
    })
  },
  
  // 添加打印方法
  printOrder: (orderData) => {
    return ipcRenderer.invoke('print-order', orderData)
  }
}


// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
// just add to the DOM global.
if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', electronAPI)
    contextBridge.exposeInMainWorld('api', api)
  } catch (error) {
    console.error(error)
  }
} else {
  window.electron = electronAPI
  window.api = api
}
